package com.leetroll.api.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.leetroll.api.mapper.MetricMapper;
import com.leetroll.api.service.MetricService;
import com.leetroll.common.entity.Metric;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class MetricServiceImpl extends SuperServiceImpl<MetricMapper, Metric> implements MetricService {

    @Override
    @Cacheable(cacheNames = "listMetricsByCat", key = "#parentId")
    public List<Metric> listByCat(Integer parentId) {
        QueryWrapper<Metric> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("parent_id", parentId);
        queryWrapper.eq("active", true);
        return this.list(queryWrapper);
    }
}
